package com.zsxb.crm.controller;
import com.zsxb.crm.annotation.Log;
import com.zsxb.crm.dto.CourseDTO;
import com.zsxb.crm.dto.CoursePageDTO;
import com.zsxb.crm.pojo.Course;

import com.zsxb.crm.result.PageResult;
import com.zsxb.crm.result.Result;
import com.zsxb.crm.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clues/course")
@Slf4j
public class CourseController {

    @Autowired
    private CourseService courseService;

    @GetMapping("/list")
    public PageResult pageQuery(CoursePageDTO dto){
        log.info("课程管理分页参数:{}",dto);
        PageResult pageResult = courseService.pageQuery(dto);
        return PageResult.success(pageResult);
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id){
        log.info("根据id查询课程信息:{}",id);
        Course course = courseService.getById(id);
        return Result.success(course);
    }


    @PutMapping
    @Log
    public Result update(@RequestBody Course course){
        log.info("更新课程信息:{}",course);
        courseService.update(course);
        return Result.success();
    }


    @DeleteMapping("/{ids}")
    @Log
    public Result delete(@PathVariable String ids){
        log.info("删除课程信息:{}",ids);
        courseService.delete(ids);
        return Result.success();
    }

    @PostMapping
    @Log
    public Result add(@RequestBody CourseDTO dto){
        log.info("新增课程信息:{}",dto);
        courseService.add(dto);
        return Result.success();
    }
    //合同处查询课程
    @GetMapping("/listselect")
    public Result listselect( CourseDTO dto){
        log.info("合同管理查询课程{}",dto);
        List<Course> courseList = courseService.listselect(dto);
        return Result.success(courseList);
    }


}
